﻿using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lime49.UI {
    /// <summary>
    /// A BulletedList which allows HTML tags in items
    /// </summary>
    public class FormattedList : BulletedList {
        protected override void Render(System.Web.UI.HtmlTextWriter writer) {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
            string rendered;

            base.Render(htmlWriter);
            rendered = Regex.Replace(sb.ToString(), "(?<!&lt;)&lt;(?!&lt;)", "<");
            rendered = Regex.Replace(rendered, "(?<!&gt;)&gt;(?!&gt;)", ">");
            rendered = Regex.Replace(rendered, "(?<!&quot;)&quot;(?!&quot;)", "\"");

            rendered = rendered.Replace("&lt;&lt;", "&lt;")
                .Replace("&gt;&gt;", "&gt;")
                .Replace("&quot;&quot;", "&quot;");

            writer.Write(rendered);
        }
    }
}